import cv2
import numpy as np

def puts_(img):
    face_cascade = cv2.CascadeClassifier("C:\ProgramData\Anaconda3\envs\pytorch\Lib\site-packages\cv2\data\haarcascade_frontalface_alt.xml")
    # eye_cascade = cv2.CascadeClassifier("C:/Users/ASUS/AppData/Roaming/Python/Python38/site-packages/cv2/data/haarcascade_eye.xml")
    gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    # img = cv2.flip(img, 1)
    faces = face_cascade.detectMultiScale(gray,1.03,5)
    max_x=0
    max_y=0
    max_w=0
    max_h=0
    if len(faces)>0:
        for faceRect in faces:
            x,y,w,h = faceRect
            if(max_w*max_h<h*w):
                max_x=x
                max_y=y
                max_w=w
                max_h=h   
            # cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
            # roi_gray = gray[y:y+h//2,x:x+w]
            # roi_color = img[y:y+h//2,x:x+w]
            # eyes = eye_cascade.detectMultiScale(roi_gray,1.1,1,cv2.CASCADE_SCALE_IMAGE,(2,2))
            # for (ex,ey,ew,eh) in eyes:
            #     cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
        img=img[max_y:max_y+max_h,max_x:max_x+max_w]
    return faces,img

# cap=cv2.VideoCapture(0)
# while  True:
#     ret,k=cap.read()
#     faces,k=puts_(k)
#     cv2.imshow("img",k)
#     if cv2.waitKey(1) & 0xFF == ord('q'):
#         break


